const app = getApp();
Page({
  data: {
    userInfo:{
      avatarUrl:''
    }
  },
  onShow() {
    this.setData({ 
      userInfo:wx.getStorageSync('userInfo'),
    }) 
  },
                
onChooseAvatar: function (res) {

  const { userInfo } = res.detail.avatarUrl
  this.setData({userInfo:res.detail})
    app.userInfo.avatarUrl = res.detail.avatarUrl
    wx.setStorageSync('userInfo', res.detail)
    console.log( "缓存头像临时Url:",wx.getStorageSync('userInfo'))
    var filePath = getApp().userInfo.avatarUrl
    console.log('头像路径filePath:',filePath)
    var fileName = Math.random().toString(36).substr(2);
    console.log('头像图片文件名fileName:',fileName)            
},
  bindKeyInput: function (e) { 
},

fromsubmit (e) {
  const nickName = e.detail.value;
  this.setData({nickName: e.detail.value,})
  console.log("nickName:",nickName)
  wx.setStorageSync('nickName', e.detail.value)
  console.log( "名字有了放缓存:",wx.getStorageSync('nickName'))
},

setBtnTap() {
      const {userInfo} = this.data
      if([userInfo.avatarUrl] == '/image/l.png') {
        wx.showToast({
          title: '头像不能为空',
          icon: 'none'
        })
      return
      }
      const {nickName} = this.data
      if(!nickName) {
        wx.showToast({
          title: '昵称不能为空',
          icon: 'none'
        })
      return
      }   
       wx.navigateBack({
       url: 'B?id=1'
      })
  },
})
